<?php
namespace app\admin\model;

use think\Model;

class Auth extends Model
{
    protected $table = 'ecm_auth_rule';
    public static function authList()
    {
        $list = Auth::select();
        return $list->toArray();
    }

    public static function authIndex($userId)
    {
        $access = AuthGroup::suffix('_access')->where('uid','=',$userId)->value('group_id');
        $group = AuthGroup::where('id','=',$access)->value('rules');
        $group = explode(',',$group);
        $list = Auth::where('id','in',$group)->select()->toArray();
        return $list;
    }
    public static function authMenu()
    {
        $list = Auth::where('pid','=','0')->select();
        return $list;
    }
    public static function getAuth($userId)
    {
        $list = self::authIndex($userId);
        $arr = [];
        foreach ($list as $v){
            if ($v['pid']==0){
                $arr[$v['id']]=$v;
                foreach ($list as $vv){
                    if ($vv['pid']==$v['id']){
                        $arr[$v['id']]['two'][$vv['id']]=$vv;
                    }
                }
            }
        }
        return $arr;
    }
    //属性列表判断显示
    public static function getIfShowNextAttr($v,$data)
    {
        if ($data['if_show']==1){
            return "<font style='color: red'>显示</font>";
        }else{
            return "<font style='color: green'>不显示</font>";
        }
    }
    //属性列表判断显示
    public static function getStatusNextAttr($v,$data)
    {
        if ($data['status']==1){
            return "<font style='color: red'>显示</font>";
        }else{
            return "<font style='color: green'>不显示</font>";
        }
    }


}